﻿namespace HRM.CORE
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraLayout;
    using DevExpress.XtraLayout.Utils;
    using APP.HELPER;
    using HRM.CORE;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;
    using Security.ERP;

    public class xucPayInsuranceAdd : Common.xucBaseAddH
    {
        private CalcEdit calNumberEmployee;
        private CalcEdit calNumberEmployeeFemale;
        private CalcEdit calQuarter;
        private CalcEdit calWage;
        private IContainer components = null;
        private TimeEdit dtMonth;
        private TimeEdit dtYear;
        private EmptySpaceItem emptySpaceItem1;
        private GroupControl groupControl1;
        private LayoutControl layoutControl1;
        private LayoutControlGroup layoutControlGroup1;
        private LayoutControlItem layoutControlItem1;
        private LayoutControlItem layoutControlItem2;
        private LayoutControlItem layoutControlItem3;
        private LayoutControlItem layoutControlItem4;
        private LayoutControlItem layoutControlItem5;
        private LayoutControlItem layoutControlItem6;
        private LayoutControlItem layoutControlItem7;
        private Guid m_PayInsuranceTableListID = Guid.Empty;
        private TextEdit txtName;

        public event SuccessEventHander Success;

        public xucPayInsuranceAdd()
        {
            this.InitializeComponent();
            this.InitComponent();
        }

        protected override void Add()
        {
            base.Add();
            HRM_PAYINSURANCE_TABLELIST hrm_payinsurance_tablelist = new HRM_PAYINSURANCE_TABLELIST();
            this.txtName.Focus();
        }

        private void calQuarter_EditValueChanging(object sender, ChangingEventArgs e)
        {
            this.txtName.Text = "Qu\x00fd " + e.NewValue.ToString() + " (Th\x00e1ng " + DateTime.Parse(this.dtMonth.EditValue.ToString()).Month.ToString() + "/" + DateTime.Parse(this.dtYear.EditValue.ToString()).Year.ToString() + ")";
        }

        public void Clear()
        {
            this.txtName.Text = "";
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void dtMonth_EditValueChanging(object sender, ChangingEventArgs e)
        {
            this.txtName.Text = "Qu\x00fd " + this.calQuarter.Text + " (Th\x00e1ng " + DateTime.Parse(e.NewValue.ToString()).Month.ToString() + "/" + DateTime.Parse(this.dtYear.EditValue.ToString()).Year.ToString() + ")";
        }

        private void dtYear_EditValueChanging(object sender, ChangingEventArgs e)
        {
            this.txtName.Text = "Qu\x00fd " + this.calQuarter.Text + " (Th\x00e1ng " + DateTime.Parse(this.dtMonth.EditValue.ToString()).Month.ToString() + "/" + DateTime.Parse(e.NewValue.ToString()).Year.ToString() + ")";
        }

        protected override void Init()
        {
        }

        private void InitComponent()
        {
            this.dtMonth.EditValue = DateTime.Now;
            this.dtYear.EditValue = DateTime.Now;
            this.calQuarter.EditValue = 1;
            HRM_INSURANCE hrm_insurance = new HRM_INSURANCE();
            this.calNumberEmployee.EditValue = hrm_insurance.GetListEmployee(0, "", 0).Rows.Count;
            this.calNumberEmployeeFemale.EditValue = hrm_insurance.GetListEmployee(0, "", 3).Rows.Count;
            HRM_SALARY_TABLELIST hrm_salary_tablelist = new HRM_SALARY_TABLELIST();
            if (hrm_salary_tablelist.Exist(DateTime.Parse(this.dtMonth.EditValue.ToString()).Month, DateTime.Parse(this.dtYear.EditValue.ToString()).Year))
            {
                hrm_salary_tablelist.Get(DateTime.Parse(this.dtMonth.EditValue.ToString()).Month, DateTime.Parse(this.dtYear.EditValue.ToString()).Year);
                this.calWage.EditValue = new HRM_SALARY().GetTotalSalary(hrm_salary_tablelist.SalaryTableListID);
            }
            else
            {
                this.calWage.EditValue = 0;
            }
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xucPayInsuranceAdd));
            this.groupControl1 = new GroupControl();
            this.layoutControl1 = new LayoutControl();
            this.calWage = new CalcEdit();
            this.calNumberEmployeeFemale = new CalcEdit();
            this.calNumberEmployee = new CalcEdit();
            this.dtYear = new TimeEdit();
            this.dtMonth = new TimeEdit();
            this.txtName = new TextEdit();
            this.calQuarter = new CalcEdit();
            this.layoutControlGroup1 = new LayoutControlGroup();
            this.layoutControlItem1 = new LayoutControlItem();
            this.layoutControlItem2 = new LayoutControlItem();
            this.layoutControlItem3 = new LayoutControlItem();
            this.layoutControlItem5 = new LayoutControlItem();
            this.layoutControlItem6 = new LayoutControlItem();
            this.layoutControlItem7 = new LayoutControlItem();
            this.emptySpaceItem1 = new EmptySpaceItem();
            this.layoutControlItem4 = new LayoutControlItem();
            ((ISupportInitialize) base.Err).BeginInit();
            base.imageCollection2.BeginInit();
            this.groupControl1.BeginInit();
            this.groupControl1.SuspendLayout();
            this.layoutControl1.BeginInit();
            this.layoutControl1.SuspendLayout();
            this.calWage.Properties.BeginInit();
            this.calNumberEmployeeFemale.Properties.BeginInit();
            this.calNumberEmployee.Properties.BeginInit();
            this.dtYear.Properties.BeginInit();
            this.dtMonth.Properties.BeginInit();
            this.txtName.Properties.BeginInit();
            this.calQuarter.Properties.BeginInit();
            this.layoutControlGroup1.BeginInit();
            this.layoutControlItem1.BeginInit();
            this.layoutControlItem2.BeginInit();
            this.layoutControlItem3.BeginInit();
            this.layoutControlItem5.BeginInit();
            this.layoutControlItem6.BeginInit();
            this.layoutControlItem7.BeginInit();
            this.emptySpaceItem1.BeginInit();
            this.layoutControlItem4.BeginInit();
            base.SuspendLayout();
            base.btnSave.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            base.btnSave.Location = new Point(0x9b, 0xc1);
            base.btnSave.TabIndex = 0;
            base.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            base.btnCancel.Location = new Point(0x163, 0xc1);
            base.btnCancel.TabIndex = 2;
            base.btnSaveNew.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            base.btnSaveNew.Location = new Point(0xfe, 0xc1);
            base.btnSaveNew.TabIndex = 1;
            base.imageCollection2.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection2.ImageStream");
            this.groupControl1.Controls.Add(this.layoutControl1);
            this.groupControl1.Dock = DockStyle.Top;
            this.groupControl1.Location = new Point(0, 0);
            this.groupControl1.Name = "groupControl1";
            this.groupControl1.Size = new Size(0x1ce, 0xb7);
            this.groupControl1.TabIndex = 0;
            this.groupControl1.Text = "Đợt Thanh To\x00e1n";
            this.layoutControl1.Controls.Add(this.calWage);
            this.layoutControl1.Controls.Add(this.calNumberEmployeeFemale);
            this.layoutControl1.Controls.Add(this.calNumberEmployee);
            this.layoutControl1.Controls.Add(this.dtYear);
            this.layoutControl1.Controls.Add(this.dtMonth);
            this.layoutControl1.Controls.Add(this.txtName);
            this.layoutControl1.Controls.Add(this.calQuarter);
            this.layoutControl1.Dock = DockStyle.Fill;
            this.layoutControl1.Location = new Point(2, 0x16);
            this.layoutControl1.Name = "layoutControl1";
            this.layoutControl1.Root = this.layoutControlGroup1;
            this.layoutControl1.Size = new Size(0x1ca, 0x9f);
            this.layoutControl1.TabIndex = 0;
            this.layoutControl1.Text = "layoutControl1";
            this.calWage.Location = new Point(0x70, 0x7f);
            this.calWage.Name = "calWage";
            this.calWage.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo), new EditorButton(ButtonPredefines.Left) });
            this.calWage.Properties.Mask.UseMaskAsDisplayFormat = true;
            this.calWage.Size = new Size(0x14e, 20);
            this.calWage.StyleController = this.layoutControl1;
            this.calWage.TabIndex = 6;
            this.calNumberEmployeeFemale.Location = new Point(0x144, 0x67);
            this.calNumberEmployeeFemale.Name = "calNumberEmployeeFemale";
            this.calNumberEmployeeFemale.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo), new EditorButton(ButtonPredefines.Left) });
            this.calNumberEmployeeFemale.Properties.Mask.UseMaskAsDisplayFormat = true;
            this.calNumberEmployeeFemale.Size = new Size(0x7a, 20);
            this.calNumberEmployeeFemale.StyleController = this.layoutControl1;
            this.calNumberEmployeeFemale.TabIndex = 5;
            this.calNumberEmployee.Location = new Point(0x70, 0x67);
            this.calNumberEmployee.Name = "calNumberEmployee";
            this.calNumberEmployee.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo), new EditorButton(ButtonPredefines.Left) });
            this.calNumberEmployee.Properties.Mask.UseMaskAsDisplayFormat = true;
            this.calNumberEmployee.Size = new Size(0x7f, 20);
            this.calNumberEmployee.StyleController = this.layoutControl1;
            this.calNumberEmployee.TabIndex = 4;
            this.dtYear.EditValue = new DateTime(0x7dc, 4, 5, 0, 0, 0, 0);
            this.dtYear.Location = new Point(0x174, 0x24);
            this.dtYear.Name = "dtYear";
            this.dtYear.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtYear.Properties.Mask.EditMask = "yyyy";
            this.dtYear.Size = new Size(0x4a, 20);
            this.dtYear.StyleController = this.layoutControl1;
            this.dtYear.TabIndex = 3;
            this.dtYear.EditValueChanging += new ChangingEventHandler(this.dtYear_EditValueChanging);
            this.dtMonth.EditValue = new DateTime(0x7dc, 4, 5, 0, 0, 0, 0);
            this.dtMonth.Location = new Point(0x70, 0x24);
            this.dtMonth.Name = "dtMonth";
            this.dtMonth.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtMonth.Properties.Mask.EditMask = "MM";
            this.dtMonth.Size = new Size(0x4a, 20);
            this.dtMonth.StyleController = this.layoutControl1;
            this.dtMonth.TabIndex = 1;
            this.dtMonth.EditValueChanging += new ChangingEventHandler(this.dtMonth_EditValueChanging);
            this.txtName.Location = new Point(0x70, 12);
            this.txtName.Name = "txtName";
            this.txtName.Properties.ReadOnly = true;
            this.txtName.Size = new Size(0x14e, 20);
            this.txtName.StyleController = this.layoutControl1;
            this.txtName.TabIndex = 0;
            int[] bits = new int[4];
            bits[0] = 1;
            this.calQuarter.EditValue = new decimal(bits);
            this.calQuarter.Location = new Point(0xec, 0x24);
            this.calQuarter.Name = "calQuarter";
            this.calQuarter.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.calQuarter.Properties.EditValueChangedFiringMode = EditValueChangedFiringMode.Buffered;
            this.calQuarter.Size = new Size(0x4d, 20);
            this.calQuarter.StyleController = this.layoutControl1;
            this.calQuarter.TabIndex = 2;
            this.calQuarter.EditValueChanging += new ChangingEventHandler(this.calQuarter_EditValueChanging);
            this.layoutControlGroup1.CustomizationFormText = "layoutControlGroup1";
            this.layoutControlGroup1.EnableIndentsWithoutBorders = DefaultBoolean.True;
            this.layoutControlGroup1.GroupBordersVisible = false;
            this.layoutControlGroup1.Items.AddRange(new BaseLayoutItem[] { this.layoutControlItem1, this.layoutControlItem2, this.layoutControlItem3, this.layoutControlItem5, this.layoutControlItem6, this.layoutControlItem7, this.emptySpaceItem1, this.layoutControlItem4 });
            this.layoutControlGroup1.Location = new Point(0, 0);
            this.layoutControlGroup1.Name = "layoutControlGroup1";
            this.layoutControlGroup1.Size = new Size(0x1ca, 0x9f);
            this.layoutControlGroup1.Spacing = new DevExpress.XtraLayout.Utils.Padding(0, 0, 0, 0);
            this.layoutControlGroup1.Text = "layoutControlGroup1";
            this.layoutControlGroup1.TextVisible = false;
            this.layoutControlItem1.AllowHtmlStringInCaption = true;
            this.layoutControlItem1.Control = this.txtName;
            this.layoutControlItem1.CustomizationFormText = "T\x00ean đợt:";
            this.layoutControlItem1.Location = new Point(0, 0);
            this.layoutControlItem1.Name = "layoutControlItem1";
            this.layoutControlItem1.Size = new Size(0x1b6, 0x18);
            this.layoutControlItem1.Text = "T\x00ean đợt <color=red>(*)</color>:";
            this.layoutControlItem1.TextSize = new Size(0x60, 14);
            this.layoutControlItem2.AllowHtmlStringInCaption = true;
            this.layoutControlItem2.Control = this.dtMonth;
            this.layoutControlItem2.CustomizationFormText = "V\x00e0o th\x00e1ng:";
            this.layoutControlItem2.Location = new Point(0, 0x18);
            this.layoutControlItem2.Name = "layoutControlItem2";
            this.layoutControlItem2.Size = new Size(0xb2, 0x18);
            this.layoutControlItem2.Text = "V\x00e0o th\x00e1ng <color=red>(*)</color>:";
            this.layoutControlItem2.TextSize = new Size(0x60, 14);
            this.layoutControlItem3.AllowHtmlStringInCaption = true;
            this.layoutControlItem3.Control = this.dtYear;
            this.layoutControlItem3.CustomizationFormText = "Năm:";
            this.layoutControlItem3.Location = new Point(0x131, 0x18);
            this.layoutControlItem3.Name = "layoutControlItem3";
            this.layoutControlItem3.Size = new Size(0x85, 0x18);
            this.layoutControlItem3.Text = "Năm <color=red>(*)</color>:";
            this.layoutControlItem3.TextAlignMode = TextAlignModeItem.CustomSize;
            this.layoutControlItem3.TextSize = new Size(50, 20);
            this.layoutControlItem3.TextToControlDistance = 5;
            this.layoutControlItem5.Control = this.calNumberEmployee;
            this.layoutControlItem5.CustomizationFormText = "Số lượng nh\x00e2n vi\x00ean:";
            this.layoutControlItem5.Location = new Point(0, 0x5b);
            this.layoutControlItem5.Name = "layoutControlItem5";
            this.layoutControlItem5.Size = new Size(0xe7, 0x18);
            this.layoutControlItem5.Text = "Số lượng nh\x00e2n vi\x00ean:";
            this.layoutControlItem5.TextSize = new Size(0x60, 13);
            this.layoutControlItem6.Control = this.calNumberEmployeeFemale;
            this.layoutControlItem6.CustomizationFormText = "trong đ\x00f3, nữ:";
            this.layoutControlItem6.Location = new Point(0xe7, 0x5b);
            this.layoutControlItem6.Name = "layoutControlItem6";
            this.layoutControlItem6.Size = new Size(0xcf, 0x18);
            this.layoutControlItem6.Text = "trong đ\x00f3, nữ:";
            this.layoutControlItem6.TextAlignMode = TextAlignModeItem.CustomSize;
            this.layoutControlItem6.TextSize = new Size(0x4c, 13);
            this.layoutControlItem6.TextToControlDistance = 5;
            this.layoutControlItem7.Control = this.calWage;
            this.layoutControlItem7.CustomizationFormText = "Quỹ lương trong th\x00e1ng:";
            this.layoutControlItem7.Location = new Point(0, 0x73);
            this.layoutControlItem7.Name = "layoutControlItem7";
            this.layoutControlItem7.Size = new Size(0x1b6, 0x18);
            this.layoutControlItem7.Text = "Quỹ lương:";
            this.layoutControlItem7.TextSize = new Size(0x60, 13);
            this.emptySpaceItem1.CustomizationFormText = "emptySpaceItem1";
            this.emptySpaceItem1.Location = new Point(0, 0x30);
            this.emptySpaceItem1.Name = "emptySpaceItem1";
            this.emptySpaceItem1.Size = new Size(0x1b6, 0x2b);
            this.emptySpaceItem1.Text = "emptySpaceItem1";
            this.emptySpaceItem1.TextSize = new Size(0, 0);
            this.layoutControlItem4.AllowHtmlStringInCaption = true;
            this.layoutControlItem4.Control = this.calQuarter;
            this.layoutControlItem4.CustomizationFormText = "Đợt b\x00e1o c\x00e1o:";
            this.layoutControlItem4.Location = new Point(0xb2, 0x18);
            this.layoutControlItem4.Name = "layoutControlItem4";
            this.layoutControlItem4.Size = new Size(0x7f, 0x18);
            this.layoutControlItem4.Text = "Qu\x00fd <color=red>(*)</color>:";
            this.layoutControlItem4.TextAlignMode = TextAlignModeItem.AutoSize;
            this.layoutControlItem4.TextSize = new Size(0x29, 14);
            this.layoutControlItem4.TextToControlDistance = 5;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.groupControl1);
            base.Name = "xucPayInsuranceAdd";
            base.Size = new Size(0x1ce, 0xe7);
            base.Controls.SetChildIndex(base.btnCancel, 0);
            base.Controls.SetChildIndex(base.btnSave, 0);
            base.Controls.SetChildIndex(base.btnSaveNew, 0);
            base.Controls.SetChildIndex(this.groupControl1, 0);
            ((ISupportInitialize) base.Err).EndInit();
            base.imageCollection2.EndInit();
            this.groupControl1.EndInit();
            this.groupControl1.ResumeLayout(false);
            this.layoutControl1.EndInit();
            this.layoutControl1.ResumeLayout(false);
            this.calWage.Properties.EndInit();
            this.calNumberEmployeeFemale.Properties.EndInit();
            this.calNumberEmployee.Properties.EndInit();
            this.dtYear.Properties.EndInit();
            this.dtMonth.Properties.EndInit();
            this.txtName.Properties.EndInit();
            this.calQuarter.Properties.EndInit();
            this.layoutControlGroup1.EndInit();
            this.layoutControlItem1.EndInit();
            this.layoutControlItem2.EndInit();
            this.layoutControlItem3.EndInit();
            this.layoutControlItem5.EndInit();
            this.layoutControlItem6.EndInit();
            this.layoutControlItem7.EndInit();
            this.emptySpaceItem1.EndInit();
            this.layoutControlItem4.EndInit();
            base.ResumeLayout(false);
        }

        private void RaiseSuccessEventHander(HRM_PAYINSURANCE_TABLELIST item)
        {
            if (this.Success != null)
            {
                this.Success(this, item);
            }
        }

        public void SetData(HRM_PAYINSURANCE_TABLELIST item)
        {
            this.m_PayInsuranceTableListID = item.PayInsuranceTableListID;
            SYS_LOG.Insert("Đợt B\x00e1o C\x00e1o", "Xem", this.m_PayInsuranceTableListID.ToString());
            this.txtName.Text = item.PayInsuranceTableListName;
            this.dtMonth.EditValue = new DateTime(item.Year, item.Month, 1);
            this.dtYear.EditValue = new DateTime(item.Year, item.Month, 1);
            this.calQuarter.EditValue = item.Quarter;
            this.calNumberEmployee.EditValue = item.NumberEmployee;
            this.calNumberEmployeeFemale.EditValue = item.NumberEmployeeFemale;
            this.calWage.EditValue = item.Wage;
        }

        protected override string uc_Change()
        {
            return string.Empty;
        }

        protected override string uc_Delete()
        {
            HRM_PAYINSURANCE_TABLELIST item = new HRM_PAYINSURANCE_TABLELIST {
                PayInsuranceTableListID = this.m_PayInsuranceTableListID
            };
            string str = item.Delete();
            if (str == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            return str;
        }

        protected override string uc_Save()
        {
            if (MyRule.Get(MyLogin.RoleId, "bbiInsurance") != "OK")
            {
                return "";
            }
            if (!MyRule.AllowAdd)
            {
                MyRule.Notify();
                return "";
            }
            SYS_LOG.Insert("Đợt B\x00e1o C\x00e1o", "Th\x00eam", this.m_PayInsuranceTableListID.ToString());
            base.SetWaitDialogCaption("Đang lưu dữ liệu...");
            Cursor.Current = Cursors.WaitCursor;
            HRM_PAYINSURANCE_TABLELIST item = new HRM_PAYINSURANCE_TABLELIST {
                PayInsuranceTableListID = Guid.NewGuid(),
                PayInsuranceTableListName = this.txtName.Text,
                Month = Convert.ToInt32(this.dtMonth.Text),
                Year = Convert.ToInt32(this.dtYear.Text),
                Quarter = Convert.ToInt32(this.calQuarter.Text),
                NumberEmployee = Convert.ToInt32(this.calNumberEmployee.EditValue.ToString()),
                NumberEmployeeFemale = Convert.ToInt32(this.calNumberEmployeeFemale.EditValue.ToString()),
                Wage = Convert.ToDecimal(this.calWage.EditValue.ToString())
            };
            string text = item.Insert();
            if (text == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            Cursor.Current = Cursors.Default;
            this.DoHide();
            if (text != "OK")
            {
                XtraMessageBox.Show(text, "Cảnh B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return text;
        }

        protected override string uc_Update()
        {
            if (MyRule.Get(MyLogin.RoleId, "bbiInsurance") != "OK")
            {
                return "";
            }
            if (!MyRule.AllowEdit)
            {
                MyRule.Notify();
                return "";
            }
            SYS_LOG.Insert("Đợt B\x00e1o C\x00e1o", "Cập Nhật", this.m_PayInsuranceTableListID.ToString());
            base.SetWaitDialogCaption("Đang cập nhật dữ liệu...");
            HRM_PAYINSURANCE_TABLELIST item = new HRM_PAYINSURANCE_TABLELIST {
                PayInsuranceTableListID = this.m_PayInsuranceTableListID,
                PayInsuranceTableListName = this.txtName.Text,
                Month = Convert.ToInt32(this.dtMonth.Text),
                Year = Convert.ToInt32(this.dtYear.Text),
                Quarter = Convert.ToInt32(this.calQuarter.Text),
                NumberEmployee = Convert.ToInt32(this.calNumberEmployee.EditValue.ToString()),
                NumberEmployeeFemale = Convert.ToInt32(this.calNumberEmployeeFemale.EditValue.ToString()),
                Wage = Convert.ToDecimal(this.calWage.EditValue.ToString())
            };
            string text = item.Update();
            if (text == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            if (text != "OK")
            {
                XtraMessageBox.Show(text, "Cảnh B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            this.DoHide();
            return text;
        }

        public delegate void SuccessEventHander(object sender, HRM_PAYINSURANCE_TABLELIST item);
    }
}

